﻿namespace IBTrader.Model
{
    using IBTrader.Modules.Configuration;
    using System;
    using System.Collections.ObjectModel;
    using System.Xml.Serialization;

    public class HistoricalContracts: ObservableCollection<HistoricalContract>
    {
    }
    public class HistoricalContract : Contract 
    {
        private string _barSize, _barType;
        private TimeSpan _barDuration;
        private DateTime _from, _to;
        private bool _onlyRealTime;
        private double _percent;

        public HistoricalContract()
        {
            SecurityType = "STK";
            Exchange = "SMART";
            Currency = "USD";
            BarSize = "1 secs";
            BarDuration = new TimeSpan(0, 30, 0);
            BarType = "TRADES";
            From = Times.Now.Date;
        }

        public string BarSize { get { return _barSize; } set { _barSize = value; Changed(() => BarSize); } }
        public string BarType { get { return _barType; } set { _barType = value; Changed(() => BarType); } }
        public DateTime From { get { return _from; } set { _from = value; Changed(() => From); } }
        public DateTime To { get { return _to; } set { _to = value; Changed(() => To); } }
        public bool OnlyRealTime { get { return _onlyRealTime; } set { _onlyRealTime = value; Changed(() => OnlyRealTime); } }
        public double Percent { get { return _percent; } set { _percent = value; Changed(() => Percent); } }

        [XmlIgnore] public TimeSpan BarDuration { get { return _barDuration; } set { _barDuration = value; Changed(() => BarDuration); } }

        [XmlElement("BarDuration")] public long BarDurationTicks { get { return _barDuration.Ticks; } set { _barDuration = new TimeSpan(value); } }
    }
}
